package com.springcloud3.event;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Service;

@Service
public class EventPublisher implements ApplicationEventPublisherAware {
    /**
     * 底层发时间的组件
     */
    ApplicationEventPublisher applicationEventPublisher;
    /**
     * 所有事件都可以发布
     * 事件是广播出去的
     * @param event
     */
    public void sendEvent(ApplicationEvent event) {
        applicationEventPublisher .publishEvent(event);
    }

    /**
     *会被调用,把真正发事件的底层组装给我们注入过来
     * @param applicationEventPublisher
     */
    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
 this.applicationEventPublisher = applicationEventPublisher;
    }
}
